package com.cabinet.web.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Controller;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.cabinet.base.util.ReadImgUtil;


@Controller
@RequestMapping("/read")
public class ImgReadController {

	/**
	 * /read/upload?name=${udto.uPhoto }
	 * @param name
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value = "/upload")
	public void readimg(String name, HttpServletResponse response) throws Exception {
		response.setContentType("image/gif;charset=utf-8");
		FileCopyUtils.copy(ReadImgUtil.get(name), response.getOutputStream());
	}
	
	
	/*@RequestMapping(value = "/upload")
	public void readimg(String name, HttpServletResponse response) throws Exception {
		response.setContentType("image/gif;charset=utf-8");
		FileCopyUtils.copy(get(name), response.getOutputStream());
	}
	
	public static byte[] get(String filename) throws IOException {
		//String path = getFilePath() + filename;
		String path = "H:\\" + filename;
		return FileUtils.readFileToByteArray(FileUtils.getFile(path));
	}*/
	
	
	
}
